using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public struct KeyCompPair {
		public string key;
		public string comp;
		public KeyCompPair(string key, string comp) {
			/* TODO: probs should copy by value? need to investigate */
			this.key = key;
			this.comp = comp;
		}
}

public interface IClickableGui {
	void RightClick(Event e);
	void LeftClick(Event e);
}

public struct MouseClickMemory {
	public bool down;
	public Vector2 pos;
	
	public MouseClickMemory(bool down, Vector2 pos) {
		this.down = down;
		this.pos = pos;
	}
}

class GuiIO : MonoBehaviour, IGlobalIO {
	List<KeyCompPair> toggles = new List<KeyCompPair>()
	{
		new KeyCompPair("Inventory", "InventoryGui"),
	};
	
	public void UpdateIO () {
		foreach (KeyCompPair p in this.toggles) {
			if (Input.GetButtonDown (p.key)) {
				IToggleGui g = (IToggleGui)this.gameObject.GetComponent(p.comp);
			
				if (g == null) {
					/* first creation of window */
					g = (IToggleGui)this.gameObject.AddComponent(p.comp);
					if (g != null) {
						g.toggle.IsOn = true;
					}
				} else {
					/* already exists, toggle state */
					g.toggle.Toggle();
				}
			}
		}
	}
	
	public static void HandleMouseClick(IClickableGui g, Event e)
	{
		if ((e != null) &&
			((e.type == EventType.MouseUp) ||
			(e.type == EventType.MouseDown))) {
			switch (e.button) {
			case (int)UtilConstants.MouseButton.Right:
				g.RightClick(e);
				break;
			case (int)UtilConstants.MouseButton.Left:
				g.LeftClick(e);
				break;
			default:
				break;
			}
		}	
	}
}
